// pages/search_main/search_main.js
const app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        attendance: [],
        page: 1,
        is_empty: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.renderAttendanceList();
    },

    /**
     * 下拉刷新
     */
    onPullDownRefresh: function () {
        wx.showLoading({
            title: '正在刷新',
        })
        this.renderAttendanceList(function () {
            setTimeout(function () {
                wx.stopPullDownRefresh();
                wx.hideLoading()
            }, 500)
        })
    },

    /**
     * 上拉分页加载
     */
    onReachBottom: function () {
        this.getAttendanceList();
    },

    //重新渲染数据
    renderAttendanceList: function (cb) {
        let setdata = {};
        setdata['attendance'] = [];
        setdata['page'] = 1;
        this.setData(setdata)
        this.getAttendanceList(cb);
    },

    //获取考勤列表
    getAttendanceList: function (cb) {
        let _this = this,
        origin = _this.data.attendance;
        app._get('/api/login/classmaster/getAttendance', {
         
        }, function (response) {
            let data = response.data.data;
            data = origin.length > 0 ? origin.concat(data) : data;
            let setdata = {};
            if (data.length == 0) {
                setdata['is_empty'] = true;
            } else {
                setdata['is_empty'] = false;
                setdata['attendance'] = data;
            }
            _this.setData(setdata);
        })
        typeof cb == 'function' && cb();
    },

})